#!/usr/bin/perl

# changelog
#
# 04.15.2011	EI	fixed up
# 04.26.11		EI	changed file checking, added xmgrace checking
# 04.28.11		EI	added -agr option
# 05.17.11		EI	made plot name optional, added -nxy option, xmgrace raw options
$version='05.17.11';

# check to see if xmgrace is installed
$foo=`xmgrace -version`;
if($? ne 0){
	print "Xmgrace not installed, or is unusuable.\n";
	exit;
}

# default arguments
$argcounter			= 0;
$startarg			= 0;
$output_type		= 'PostScript';
$output_ext			= 'ps';
$outputpipe			= " >/dev/null 2>&1";
$agr_output			= 'false';
$xmgrace_options	= '';
$nxy_input			= 'false';
$output_name 		= 'default';

while ( $argcounter <= $#ARGV )
{
	if ( $ARGV[ $argcounter ] eq "-out" )
	{
		$output_type = uc($ARGV[ $argcounter +1 ]);
		$output_ext = $ARGV[ $argcounter +1 ];
		$argcounter++;
		$startarg+=2;
	}
	elsif ($ARGV[ $argcounter ] eq "-v"){
		$outputpipe = '';
		$startarg++;
	}
	elsif ($ARGV[ $argcounter ] eq "-agr"){
		$agr_output = 'true';
		$startarg++;
	}
	elsif ($ARGV[ $argcounter ] eq "-xmgr"){
		$xmgrace_options .= ' '.$ARGV[ $argcounter +1 ];
		$argcounter++;
		$startarg+=2;
	}
	elsif ($ARGV[ $argcounter ] eq "-nxy"){
		$nxy_input = 'true';
		$startarg++;
	}
	elsif ($ARGV[ $argcounter ] eq "-version"){
		print $version."\n";
		exit;
	}
	elsif ($ARGV[ $argcounter ] eq "-h"){
		print "saxsplot (-v) (-out [pdf|png|svg]) (-xmgr 'xmgrace options') <file 1> ... <file n> (<plotname>)\n";
		exit;
	}
	$argcounter++;
}

# place valid input files into an array
@input_files = ();
for($i=$startarg; $i<=$#ARGV; $i++)
{
	if (-e $ARGV[$i]){
		push(@input_files,$ARGV[$i]);
	}elsif($i eq $#ARGV){
		$output_name = $ARGV[$i]; # the output file name can be the last argument
	}else{
		print "File \"".$ARGV[$i]."\" not readable.\n";
	}
}

if ($#input_files == -1){
	print "No valid files provided.\n".$#input_files;
	exit;
}

# write the xmgrace plotting parameters
write_pars();

$title="\"SAXS Scattering Profiles\"";
if($output_name ne 'default'){ $subtitle="$output_name, generated by saxsplot"; }

$s ="xmgrace -p /tmp/xmgrace.par -pexec 'title $title' -pexec 'subtitle \"$subtitle\"'";
$s.=" -autoscale xy";
if($nxy_input eq 'false'){
	$s.=" -settype xy";
}else{
	$s.=" -pexec 'legend off'";
}

# append the block data files or the nxy format file(s)
for($i=0; $i<=$#input_files; $i++)
{
	if ($nxy_input eq 'false'){
		$s.=" -block '".$input_files[$i]."' -bxy 1:2";
		$s.=" -pexec 's$i legend \"".$input_files[$i]."\"'";	
	}
	else
	{
		$s.=" -nxy '".$input_files[$i]."'";
	}
}

# append any user-specified options
if($xmgrace_options ne ''){ $s .= " $xmgrace_options"; }

# do we save the raw xmgrace file?
if ($agr_output eq 'true'){
	$s.= " -saveall ".$output_name.".agr";
}

# append the output parameters 
$s.= " -hardcopy -hdevice $output_type -printfile '".$output_name.".$output_ext' $outputpipe";

`$s`;
`rm /tmp/xmgrace.par`;

sub write_pars
{
	$string = <<int_END;
# Grace project file
#
version 50122
page size 792, 612
page scroll 5%
page inout 5%
link page off
map font 8 to "Courier", "Courier"
map font 10 to "Courier-Bold", "Courier-Bold"
map font 11 to "Courier-BoldOblique", "Courier-BoldOblique"
map font 9 to "Courier-Oblique", "Courier-Oblique"
map font 4 to "Helvetica", "Helvetica"
map font 6 to "Helvetica-Bold", "Helvetica-Bold"
map font 7 to "Helvetica-BoldOblique", "Helvetica-BoldOblique"
map font 15 to "Helvetica-Narrow", "Helvetica-Narrow"
map font 16 to "Helvetica-Narrow-Bold", "Helvetica-Narrow-Bold"
map font 17 to "Helvetica-Narrow-BoldOblique", "Helvetica-Narrow-BoldOblique"
map font 18 to "Helvetica-Narrow-Oblique", "Helvetica-Narrow-Oblique"
map font 5 to "Helvetica-Oblique", "Helvetica-Oblique"
map font 20 to "NewCenturySchlbk-Bold", "NewCenturySchlbk-Bold"
map font 21 to "NewCenturySchlbk-BoldItalic", "NewCenturySchlbk-BoldItalic"
map font 22 to "NewCenturySchlbk-Italic", "NewCenturySchlbk-Italic"
map font 23 to "NewCenturySchlbk-Roman", "NewCenturySchlbk-Roman"
map font 24 to "Palatino-Bold", "Palatino-Bold"
map font 25 to "Palatino-BoldItalic", "Palatino-BoldItalic"
map font 26 to "Palatino-Italic", "Palatino-Italic"
map font 27 to "Palatino-Roman", "Palatino-Roman"
map font 35 to "Symbol", "Symbol"
map font 2 to "Times-Bold", "Times-Bold"
map font 3 to "Times-BoldItalic", "Times-BoldItalic"
map font 1 to "Times-Italic", "Times-Italic"
map font 0 to "Times-Roman", "Times-Roman"
map font 33 to "ZapfChancery-MediumItalic", "ZapfChancery-MediumItalic"
map font 13 to "ZapfDingbats", "ZapfDingbats"
map color 0 to (255, 255, 255), "white"
map color 1 to (0, 0, 0), "black"
map color 2 to (255, 0, 0), "red"
map color 3 to (0, 255, 0), "green"
map color 4 to (0, 0, 255), "blue"
map color 5 to (255, 255, 0), "yellow"
map color 6 to (188, 143, 143), "brown"
map color 7 to (220, 220, 220), "grey"
map color 8 to (148, 0, 211), "violet"
map color 9 to (0, 255, 255), "cyan"
map color 10 to (255, 0, 255), "magenta"
map color 11 to (255, 165, 0), "orange"
map color 12 to (114, 33, 188), "indigo"
map color 13 to (103, 7, 72), "maroon"
map color 14 to (64, 224, 208), "turquoise"
map color 15 to (0, 139, 0), "green4"
reference date 0
date wrap off
date wrap year 1950
default linewidth 1.0
default linestyle 1
default color 1
default pattern 1
default font 0
default char size 1.000000
default symbol size 1.000000
background color 0
page background fill on
timestamp off
timestamp 0.03, 0.03
timestamp color 1
timestamp rot 0
timestamp font 0
timestamp char size 1.000000
timestamp def "Mon Feb  1 16:59:29 2010"
r0 off
link r0 to g0
r0 type above
r0 linestyle 1
r0 linewidth 1.0
r0 color 1
r0 line 0, 0, 0, 0
r1 off
link r1 to g0
r1 type above
r1 linestyle 1
r1 linewidth 1.0
r1 color 1
r1 line 0, 0, 0, 0
r2 off
link r2 to g0
r2 type above
r2 linestyle 1
r2 linewidth 1.0
r2 color 1
r2 line 0, 0, 0, 0
r3 off
link r3 to g0
r3 type above
r3 linestyle 1
r3 linewidth 1.0
r3 color 1
r3 line 0, 0, 0, 0
r4 off
link r4 to g0
r4 type above
r4 linestyle 1
r4 linewidth 1.0
r4 color 1
r4 line 0, 0, 0, 0
g0 on
g0 hidden false
g0 type XY
g0 stacked false
g0 bar hgap 0.000000
g0 fixedpoint off
g0 fixedpoint type 0
g0 fixedpoint xy 0.000000, 0.000000
g0 fixedpoint format general general
g0 fixedpoint prec 6, 6
with g0
    world 0.01, 1, 0.32, 1000
    stack world 0, 0, 0, 0
    znorm 1
    view 0.150000, 0.150000, 1.150000, 0.850000
    title "SAXS Radiation Damage Analysis"
    title font 0
    title size 1.500000
    title color 1
    subtitle "First and last 1-second frame comparisons"
    subtitle font 0
    subtitle size 1.000000
    subtitle color 1
    xaxes scale Normal
    yaxes scale Logarithmic
    xaxes invert off
    yaxes invert off
    xaxis  on
    xaxis  type zero false
    xaxis  offset 0.000000 , 0.000000
    xaxis  bar on
    xaxis  bar color 1
    xaxis  bar linestyle 1
    xaxis  bar linewidth 1.0
    xaxis  label "q (1/\\cE\\C)"
    xaxis  label layout para
    xaxis  label place auto
    xaxis  label char size 1.000000
    xaxis  label font 0
    xaxis  label color 1
    xaxis  label place normal
    xaxis  tick on
    xaxis  tick major 0.1
    xaxis  tick minor ticks 1
    xaxis  tick default 6
    xaxis  tick place rounded true
    xaxis  tick in
    xaxis  tick major size 1.000000
    xaxis  tick major color 1
    xaxis  tick major linewidth 1.0
    xaxis  tick major linestyle 1
    xaxis  tick major grid off
    xaxis  tick minor color 1
    xaxis  tick minor linewidth 1.0
    xaxis  tick minor linestyle 1
    xaxis  tick minor grid off
    xaxis  tick minor size 0.500000
    xaxis  ticklabel on
    xaxis  ticklabel format general
    xaxis  ticklabel prec 5
    xaxis  ticklabel formula ""
    xaxis  ticklabel append ""
    xaxis  ticklabel prepend ""
    xaxis  ticklabel angle 0
    xaxis  ticklabel skip 0
    xaxis  ticklabel stagger 0
    xaxis  ticklabel place normal
    xaxis  ticklabel offset auto
    xaxis  ticklabel offset 0.000000 , 0.010000
    xaxis  ticklabel start type auto
    xaxis  ticklabel start 0.000000
    xaxis  ticklabel stop type auto
    xaxis  ticklabel stop 0.000000
    xaxis  ticklabel char size 1.000000
    xaxis  ticklabel font 0
    xaxis  ticklabel color 1
    xaxis  tick place normal
    xaxis  tick spec type none
    yaxis  on
    yaxis  type zero false
    yaxis  offset 0.000000 , 0.000000
    yaxis  bar on
    yaxis  bar color 1
    yaxis  bar linestyle 1
    yaxis  bar linewidth 1.0
    yaxis  label "I(q), Intensity"
    yaxis  label layout para
    yaxis  label place auto
    yaxis  label char size 1.000000
    yaxis  label font 0
    yaxis  label color 1
    yaxis  label place normal
    yaxis  tick on
    yaxis  tick major 100
    yaxis  tick minor ticks 9
    yaxis  tick default 6
    yaxis  tick place rounded true
    yaxis  tick in
    yaxis  tick major size 1.000000
    yaxis  tick major color 1
    yaxis  tick major linewidth 1.0
    yaxis  tick major linestyle 1
    yaxis  tick major grid off
    yaxis  tick minor color 1
    yaxis  tick minor linewidth 1.0
    yaxis  tick minor linestyle 1
    yaxis  tick minor grid off
    yaxis  tick minor size 0.500000
    yaxis  ticklabel on
    yaxis  ticklabel format general
    yaxis  ticklabel prec 5
    yaxis  ticklabel formula ""
    yaxis  ticklabel append ""
    yaxis  ticklabel prepend ""
    yaxis  ticklabel angle 0
    yaxis  ticklabel skip 0
    yaxis  ticklabel stagger 0
    yaxis  ticklabel place normal
    yaxis  ticklabel offset auto
    yaxis  ticklabel offset 0.000000 , 0.010000
    yaxis  ticklabel start type auto
    yaxis  ticklabel start 0.000000
    yaxis  ticklabel stop type auto
    yaxis  ticklabel stop 0.000000
    yaxis  ticklabel char size 1.000000
    yaxis  ticklabel font 0
    yaxis  ticklabel color 1
    yaxis  tick place normal
    yaxis  tick spec type none
    altxaxis  off
    altyaxis  off
    legend on
    legend loctype view
    legend 0.85, 0.8
    legend box color 1
    legend box pattern 1
    legend box linewidth 1.0
    legend box linestyle 1
    legend box fill color 0
    legend box fill pattern 1
    legend font 0
    legend char size 1.000000
    legend color 1
    legend length 4
    legend vgap 1
    legend hgap 1
    legend invert false
    frame type 0
    frame linestyle 1
    frame linewidth 1.0
    frame color 1
    frame pattern 1
    frame background color 0
    frame background pattern 0
    s0 hidden false
    s0 type xy
    s0 symbol 0
    s0 symbol size 1.000000
    s0 symbol color 1
    s0 symbol pattern 1
    s0 symbol fill color 1
    s0 symbol fill pattern 0
    s0 symbol linewidth 1.0
    s0 symbol linestyle 1
    s0 symbol char 65
    s0 symbol char font 0
    s0 symbol skip 0
    s0 line type 1
    s0 line linestyle 1
    s0 line linewidth 1.0
    s0 line color 1
    s0 line pattern 1
    s0 baseline type 0
    s0 baseline off
    s0 dropline off
    s0 fill type 0
    s0 fill rule 0
    s0 fill color 1
    s0 fill pattern 1
    s0 avalue off
    s0 avalue type 2
    s0 avalue char size 1.000000
    s0 avalue font 0
    s0 avalue color 1
    s0 avalue rot 0
    s0 avalue format general
    s0 avalue prec 3
    s0 avalue prepend ""
    s0 avalue append ""
    s0 avalue offset 0.000000 , 0.000000
    s0 errorbar on
    s0 errorbar place both
    s0 errorbar color 1
    s0 errorbar pattern 1
    s0 errorbar size 1.000000
    s0 errorbar linewidth 1.0
    s0 errorbar linestyle 1
    s0 errorbar riser linewidth 1.0
    s0 errorbar riser linestyle 1
    s0 errorbar riser clip off
    s0 errorbar riser clip length 0.100000
    s0 comment "rad_damage.dat"
    s0 legend  "A-series 1"
    s1 hidden false
    s1 type xy
    s1 symbol 0
    s1 symbol size 1.000000
    s1 symbol color 2
    s1 symbol pattern 1
    s1 symbol fill color 2
    s1 symbol fill pattern 0
    s1 symbol linewidth 1.0
    s1 symbol linestyle 1
    s1 symbol char 65
    s1 symbol char font 0
    s1 symbol skip 0
    s1 line type 1
    s1 line linestyle 1
    s1 line linewidth 1.0
    s1 line color 2
    s1 line pattern 1
    s1 baseline type 0
    s1 baseline off
    s1 dropline off
    s1 fill type 0
    s1 fill rule 0
    s1 fill color 1
    s1 fill pattern 1
    s1 avalue off
    s1 avalue type 2
    s1 avalue char size 1.000000
    s1 avalue font 0
    s1 avalue color 1
    s1 avalue rot 0
    s1 avalue format general
    s1 avalue prec 3
    s1 avalue prepend ""
    s1 avalue append ""
    s1 avalue offset 0.000000 , 0.000000
    s1 errorbar on
    s1 errorbar place both
    s1 errorbar color 2
    s1 errorbar pattern 1
    s1 errorbar size 1.000000
    s1 errorbar linewidth 1.0
    s1 errorbar linestyle 1
    s1 errorbar riser linewidth 1.0
    s1 errorbar riser linestyle 1
    s1 errorbar riser clip off
    s1 errorbar riser clip length 0.100000
    s1 comment "rad_damage.dat"
    s1 legend  "A-series 3"
    s2 hidden false
    s2 type xy
    s2 symbol 0
    s2 symbol size 1.000000
    s2 symbol color 3
    s2 symbol pattern 1
    s2 symbol fill color 3
    s2 symbol fill pattern 0
    s2 symbol linewidth 1.0
    s2 symbol linestyle 1
    s2 symbol char 65
    s2 symbol char font 0
    s2 symbol skip 0
    s2 line type 1
    s2 line linestyle 1
    s2 line linewidth 1.0
    s2 line color 3
    s2 line pattern 1
    s2 baseline type 0
    s2 baseline off
    s2 dropline off
    s2 fill type 0
    s2 fill rule 0
    s2 fill color 1
    s2 fill pattern 1
    s2 avalue off
    s2 avalue type 2
    s2 avalue char size 1.000000
    s2 avalue font 0
    s2 avalue color 1
    s2 avalue rot 0
    s2 avalue format general
    s2 avalue prec 3
    s2 avalue prepend ""
    s2 avalue append ""
    s2 avalue offset 0.000000 , 0.000000
    s2 errorbar on
    s2 errorbar place both
    s2 errorbar color 3
    s2 errorbar pattern 1
    s2 errorbar size 1.000000
    s2 errorbar linewidth 1.0
    s2 errorbar linestyle 1
    s2 errorbar riser linewidth 1.0
    s2 errorbar riser linestyle 1
    s2 errorbar riser clip off
    s2 errorbar riser clip length 0.100000
    s2 comment "rad_damage.dat"
    s2 legend  "B-series 1"
    s3 hidden false
    s3 type xy
    s3 symbol 0
    s3 symbol size 1.000000
    s3 symbol color 4
    s3 symbol pattern 1
    s3 symbol fill color 4
    s3 symbol fill pattern 0
    s3 symbol linewidth 1.0
    s3 symbol linestyle 1
    s3 symbol char 65
    s3 symbol char font 0
    s3 symbol skip 0
    s3 line type 1
    s3 line linestyle 1
    s3 line linewidth 1.0
    s3 line color 4
    s3 line pattern 1
    s3 baseline type 0
    s3 baseline off
    s3 dropline off
    s3 fill type 0
    s3 fill rule 0
    s3 fill color 1
    s3 fill pattern 1
    s3 avalue off
    s3 avalue type 2
    s3 avalue char size 1.000000
    s3 avalue font 0
    s3 avalue color 1
    s3 avalue rot 0
    s3 avalue format general
    s3 avalue prec 3
    s3 avalue prepend ""
    s3 avalue append ""
    s3 avalue offset 0.000000 , 0.000000
    s3 errorbar on
    s3 errorbar place both
    s3 errorbar color 4
    s3 errorbar pattern 1
    s3 errorbar size 1.000000
    s3 errorbar linewidth 1.0
    s3 errorbar linestyle 1
    s3 errorbar riser linewidth 1.0
    s3 errorbar riser linestyle 1
    s3 errorbar riser clip off
    s3 errorbar riser clip length 0.100000
    s3 comment "rad_damage.dat"
    s3 legend  "B-series 3"
    s4 hidden false
    s4 type xy
    s4 symbol 0
    s4 symbol size 1.000000
    s4 symbol color 5
    s4 symbol pattern 1
    s4 symbol fill color 5
    s4 symbol fill pattern 0
    s4 symbol linewidth 1.0
    s4 symbol linestyle 1
    s4 symbol char 65
    s4 symbol char font 0
    s4 symbol skip 0
    s4 line type 1
    s4 line linestyle 1
    s4 line linewidth 1.0
    s4 line color 5
    s4 line pattern 1
    s4 baseline type 0
    s4 baseline off
    s4 dropline off
    s4 fill type 0
    s4 fill rule 0
    s4 fill color 1
    s4 fill pattern 1
    s4 avalue off
    s4 avalue type 2
    s4 avalue char size 1.000000
    s4 avalue font 0
    s4 avalue color 1
    s4 avalue rot 0
    s4 avalue format general
    s4 avalue prec 3
    s4 avalue prepend ""
    s4 avalue append ""
    s4 avalue offset 0.000000 , 0.000000
    s4 errorbar on
    s4 errorbar place both
    s4 errorbar color 5
    s4 errorbar pattern 1
    s4 errorbar size 1.000000
    s4 errorbar linewidth 1.0
    s4 errorbar linestyle 1
    s4 errorbar riser linewidth 1.0
    s4 errorbar riser linestyle 1
    s4 errorbar riser clip off
    s4 errorbar riser clip length 0.100000
    s4 comment "rad_damage.dat"
    s4 legend  "C-series 1"
    s5 hidden false
    s5 type xy
    s5 symbol 0
    s5 symbol size 1.000000
    s5 symbol color 12
    s5 symbol pattern 1
    s5 symbol fill color 12
    s5 symbol fill pattern 0
    s5 symbol linewidth 1.0
    s5 symbol linestyle 1
    s5 symbol char 65
    s5 symbol char font 0
    s5 symbol skip 0
    s5 line type 1
    s5 line linestyle 1
    s5 line linewidth 1.0
    s5 line color 12
    s5 line pattern 1
    s5 baseline type 0
    s5 baseline off
    s5 dropline off
    s5 fill type 0
    s5 fill rule 0
    s5 fill color 1
    s5 fill pattern 1
    s5 avalue off
    s5 avalue type 2
    s5 avalue char size 1.000000
    s5 avalue font 0
    s5 avalue color 1
    s5 avalue rot 0
    s5 avalue format general
    s5 avalue prec 3
    s5 avalue prepend ""
    s5 avalue append ""
    s5 avalue offset 0.000000 , 0.000000
    s5 errorbar on
    s5 errorbar place both
    s5 errorbar color 12
    s5 errorbar pattern 1
    s5 errorbar size 1.000000
    s5 errorbar linewidth 1.0
    s5 errorbar linestyle 1
    s5 errorbar riser linewidth 1.0
    s5 errorbar riser linestyle 1
    s5 errorbar riser clip off
    s5 errorbar riser clip length 0.100000
    s5 comment "rad_damage.dat"
    s5 legend  "C-series 3"
    s6 hidden false
    s6 type xy
    s6 symbol 0
    s6 symbol size 1.000000
    s6 symbol color 7
    s6 symbol pattern 1
    s6 symbol fill color 7
    s6 symbol fill pattern 0
    s6 symbol linewidth 1.0
    s6 symbol linestyle 1
    s6 symbol char 65
    s6 symbol char font 0
    s6 symbol skip 0
    s6 line type 1
    s6 line linestyle 1
    s6 line linewidth 1.0
    s6 line color 7
    s6 line pattern 1
    s6 baseline type 0
    s6 baseline off
    s6 dropline off
    s6 fill type 0
    s6 fill rule 0
    s6 fill color 1
    s6 fill pattern 1
    s6 avalue off
    s6 avalue type 2
    s6 avalue char size 1.000000
    s6 avalue font 0
    s6 avalue color 1
    s6 avalue rot 0
    s6 avalue format general
    s6 avalue prec 3
    s6 avalue prepend ""
    s6 avalue append ""
    s6 avalue offset 0.000000 , 0.000000
    s6 errorbar on
    s6 errorbar place both
    s6 errorbar color 7
    s6 errorbar pattern 1
    s6 errorbar size 1.000000
    s6 errorbar linewidth 1.0
    s6 errorbar linestyle 1
    s6 errorbar riser linewidth 1.0
    s6 errorbar riser linestyle 1
    s6 errorbar riser clip off
    s6 errorbar riser clip length 0.100000
    s6 comment "rad_damage.dat"
    s6 legend  "D-series 1"
    s7 hidden false
    s7 type xy
    s7 symbol 0
    s7 symbol size 1.000000
    s7 symbol color 8
    s7 symbol pattern 1
    s7 symbol fill color 8
    s7 symbol fill pattern 0
    s7 symbol linewidth 1.0
    s7 symbol linestyle 1
    s7 symbol char 65
    s7 symbol char font 0
    s7 symbol skip 0
    s7 line type 1
    s7 line linestyle 1
    s7 line linewidth 1.0
    s7 line color 8
    s7 line pattern 1
    s7 baseline type 0
    s7 baseline off
    s7 dropline off
    s7 fill type 0
    s7 fill rule 0
    s7 fill color 1
    s7 fill pattern 1
    s7 avalue off
    s7 avalue type 2
    s7 avalue char size 1.000000
    s7 avalue font 0
    s7 avalue color 1
    s7 avalue rot 0
    s7 avalue format general
    s7 avalue prec 3
    s7 avalue prepend ""
    s7 avalue append ""
    s7 avalue offset 0.000000 , 0.000000
    s7 errorbar on
    s7 errorbar place both
    s7 errorbar color 8
    s7 errorbar pattern 1
    s7 errorbar size 1.000000
    s7 errorbar linewidth 1.0
    s7 errorbar linestyle 1
    s7 errorbar riser linewidth 1.0
    s7 errorbar riser linestyle 1
    s7 errorbar riser clip off
    s7 errorbar riser clip length 0.100000
    s7 comment "rad_damage.dat"
    s7 legend  "D-series 3"
int_END
	open(OUTPUT, ">/tmp/xmgrace.par") or die("Can't open 'xmgrace.par' for writing: $!");
	print OUTPUT $string;
	close(OUTPUT);
}